import moment from 'moment'

// 生成模拟的今日课程数据
export const mockTodayCourses = [
  {
    id: '1001',
    courseName: '英语口语进阶',
    startTime: '09:00',
    endTime: '10:30',
    location: 'A101教室',
    className: '英语提高班',
    studentCount: 25
  },
  {
    id: '1002',
    courseName: '数学奥林匹克',
    startTime: '13:30',
    endTime: '15:00',
    location: 'B202教室',
    className: '数学竞赛班',
    studentCount: 18
  },
  {
    id: '1003',
    courseName: '编程基础',
    startTime: '16:00',
    endTime: '17:30',
    location: '电脑教室',
    className: '编程入门班',
    studentCount: 22
  }
]

// 生成模拟的学生数据
export const getMockStudents = (courseId) => {
  const baseStudents = [
    // 英语口语进阶班学生
    [
      { studentId: '2023001', studentName: '张三' },
      { studentId: '2023002', studentName: '李四' },
      { studentId: '2023003', studentName: '王五' },
      { studentId: '2023004', studentName: '赵六' },
      { studentId: '2023005', studentName: '钱七' },
      { studentId: '2023006', studentName: '孙八' },
      { studentId: '2023007', studentName: '周九' },
      { studentId: '2023008', studentName: '吴十' },
      { studentId: '2023009', studentName: '郑十一' },
      { studentId: '2023010', studentName: '王十二' }
    ],
    // 数学奥林匹克班学生
    [
      { studentId: '2023011', studentName: '刘十三' },
      { studentId: '2023012', studentName: '陈十四' },
      { studentId: '2023013', studentName: '杨十五' },
      { studentId: '2023014', studentName: '黄十六' },
      { studentId: '2023015', studentName: '周十七' },
      { studentId: '2023016', studentName: '吴十八' },
      { studentId: '2023017', studentName: '郑十九' },
      { studentId: '2023018', studentName: '王二十' }
    ],
    // 编程基础班学生
    [
      { studentId: '2023019', studentName: '李二十一' },
      { studentId: '2023020', studentName: '张二十二' },
      { studentId: '2023021', studentName: '刘二十三' },
      { studentId: '2023022', studentName: '陈二十四' },
      { studentId: '2023023', studentName: '杨二十五' },
      { studentId: '2023024', studentName: '黄二十六' },
      { studentId: '2023025', studentName: '周二十七' },
      { studentId: '2023026', studentName: '吴二十八' },
      { studentId: '2023027', studentName: '郑二十九' },
      { studentId: '2023028', studentName: '王三十' },
      { studentId: '2023029', studentName: '李三十一' },
      { studentId: '2023030', studentName: '张三十二' }
    ]
  ]

  // 根据课程ID返回对应的学生列表
  const courseIndex = courseId === '1001' ? 0 : courseId === '1002' ? 1 : 2
  return baseStudents[courseIndex]
}

// 生成模拟的签到记录
export const getMockSignInRecords = (courseId) => {
  const students = getMockStudents(courseId)
  const records = []
  const now = moment()
  
  // 随机生成部分学生的签到记录
  students.forEach((student, index) => {
    // 70%的学生已签到
    if (Math.random() < 0.7) {
      // 生成课程开始时间到当前时间之间的随机签到时间
      const course = mockTodayCourses.find(c => c.id === courseId)
      const startTime = moment(course.startTime, 'HH:mm')
      const randomMinutes = Math.floor(Math.random() * (now.diff(startTime, 'minutes')))
      const signInTime = startTime.add(randomMinutes, 'minutes').format('YYYY-MM-DD HH:mm:ss')
      
      records.push({
        studentId: student.studentId,
        signInTime: signInTime
      })
    }
  })
  
  return records
}